<html>
<head><meta charset="utf-8"><title>refer to own crate via absolute path? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html">refer to own crate via absolute path?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227561068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/refer%20to%20own%20crate%20via%20absolute%20path%3F/near/227561068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html#227561068">(Feb 24 2021 at 07:57)</a>:</h4>
<p>I have two crates, <code>foo</code> and <code>foo_derive</code>, where the latter defines a <code>derive(Foo)</code> handler which produces an implementation of <code>impl ::foo::Foo for T { ... }</code>. This works great for crate <code>bar</code> that imports both crates, but what if I want to use the derive handler inside crate <code>foo</code> as well? I'm getting an error that <code>::foo::Foo</code> can't be resolved (although <code>crate::Foo</code> or just <code>Foo</code> would work).</p>



<a name="227566255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/refer%20to%20own%20crate%20via%20absolute%20path%3F/near/227566255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html#227566255">(Feb 24 2021 at 08:49)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=bb4cd9089d801422a6b58f26359ad55b"><code>extern crate self as foo</code></a>?</p>



<a name="227567169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/refer%20to%20own%20crate%20via%20absolute%20path%3F/near/227567169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html#227567169">(Feb 24 2021 at 08:58)</a>:</h4>
<p>ooh, mind bending</p>



<a name="227567179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/refer%20to%20own%20crate%20via%20absolute%20path%3F/near/227567179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html#227567179">(Feb 24 2021 at 08:58)</a>:</h4>
<p>is it extern or not? <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="227603917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/refer%20to%20own%20crate%20via%20absolute%20path%3F/near/227603917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html#227603917">(Feb 24 2021 at 14:14)</a>:</h4>
<p>In SNAFU, I have <code>#[snafu(crate_root(...))]</code> that can be applied in addition. This allows for people to rename my crates and still use the derive.</p>



<a name="227604036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/refer%20to%20own%20crate%20via%20absolute%20path%3F/near/227604036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html#227604036">(Feb 24 2021 at 14:15)</a>:</h4>
<p>When I use the derive (<code>foo_derive</code>) in the crate (<code>foo</code>), it looks like:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[derive(Debug, Snafu)]</span><span class="w"></span>
<span class="cp">#[snafu(crate_root(crate))]</span><span class="w"></span>
</code></pre></div>



<a name="227604328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/refer%20to%20own%20crate%20via%20absolute%20path%3F/near/227604328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html#227604328">(Feb 24 2021 at 14:17)</a>:</h4>
<p>And if someone else decides to rename the <code>snafu</code> crate for whatever reason (maybe to have both <code>snafu_06</code> and <code>snafu_07</code>), they can use the same mechanism.</p>



<a name="227645519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/refer%20to%20own%20crate%20via%20absolute%20path%3F/near/227645519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html#227645519">(Feb 24 2021 at 18:12)</a>:</h4>
<p><a href="https://docs.rs/proc-macro-crate">https://docs.rs/proc-macro-crate</a> can also help when crates are renamed, but it won't work in "self" crates or macro re-exports.</p>



<a name="227663286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/refer%20to%20own%20crate%20via%20absolute%20path%3F/near/227663286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/refer.20to.20own.20crate.20via.20absolute.20path.3F.html#227663286">(Feb 24 2021 at 20:09)</a>:</h4>
<p>I knew of that crate, but I never looked to see how it worked:</p>
<blockquote>
<p>CARGO_MANIFEST_DIR will be used to find the current active Cargo.toml and this Cargo.toml is searched for the desired crate.</p>
</blockquote>
<p>Now I'm sad.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>